package com.sdonkey.score.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * Created by 75306469@qq.com on 2016/11/1.
 */
public class ResponseUtil {


    public static JSONObject createError(JSONObject error) {
        JSONObject result = new JSONObject();
        result.put("error", error);
        return result;
    }

    public static String createError(String code) {
        JSONObject result = new JSONObject();
        result.put("code", code);
        return createError(result).toString();
    }

    public static String createError(String code, String msg) {
        JSONObject result = new JSONObject();
        result.put("code", code);
        result.put("msg", msg);
        return createError(result).toString();
    }

    public static String createError(String code, String msg, String... data) {
        JSONObject result = new JSONObject();
        result.put("code", code);
        result.put("msg", msg);
        result.put("data", data);
        return createError(result).toString();
    }

    public static String createError(String code, String msg, JSONArray data) {
        JSONObject result = new JSONObject();
        result.put("code", code);
        result.put("msg", msg);
        result.put("data", data);
        return createError(result).toString();
    }


    public static JSONObject createErrorInfo(String data, String msg) {
        JSONObject result = new JSONObject();
        result.put("msg", msg);
        result.put("data", data);
        return result;
    }

    public static JSONObject createResultBlank() {
        JSONArray result = new JSONArray();
        JSONObject r = new JSONObject();
        r.put("result", result);
        return r;
    }

    public static JSONObject createResultBlank(JSONObject result) {
        JSONObject r = new JSONObject();
        r.put("result", result);
        return r;
    }

    public static JSONObject createResultBlank(JSONArray result) {
        JSONObject r = new JSONObject();
        r.put("result", result);
        return r;
    }

    public static JSONObject createResultBlank(String result) {
        JSONObject r = new JSONObject();
        r.put("result", result);
        return r;
    }
    public static String createResultBlank(String key,Object val) {
        JSONObject r = new JSONObject();
        r.put(key, val);
        return r.toString();
    }

    public static String createSuccess() {
        JSONObject result = new JSONObject();
        return result.toString();
    }
}
